#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

/*
输入：	./open 1.txt
解析： argc = 2
	   argv[0] = "./open"
	   argv[1] = "1.txt"
*/
int main(int argc,char **argv)
{
	int fd;
	if(argc!=2)
	{
		printf("usage:%s <filename>\n",argv[0]);
		return -1;
	}
	fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC,0600);
	if(fd<0){
		printf("can not open file %s\n",argv[1]);//打印报错
		printf("errno = %d\n",errno);	//出错的数量
		printf("err:%s\n",strerror(errno));//打印错误
		//perror("open");//打印错误	
	}
	else
	{
		printf("fd = %d\n",fd);
	}
	while(1)
	{
			sleep(10);
	}
	close(fd);
	return 0;	
}


